package cn.stronglink.assetmanage.business.inspection.view.wait;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ExpandableListView;
import android.widget.LinearLayout;
import android.widget.TextView;


import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.stronglink.assetmanage.MainActivity;
import cn.stronglink.assetmanage.R;

import cn.stronglink.assetmanage.business.inspection.adapter.PatrolListAdapter;
import cn.stronglink.assetmanage.business.inspection.adapter.PatrolOrderAdapter;
import cn.stronglink.assetmanage.business.inspection.view.IPatrolInView;
import cn.stronglink.assetmanage.business.inspection.view.PatrolDetail.PatrolDetailFragment;
import cn.stronglink.assetmanage.business.inventory.view.detail.InventoryDetailFragment;
import cn.stronglink.assetmanage.entity.InventoryDetail;
import cn.stronglink.assetmanage.entity.Patrol;
import cn.stronglink.assetmanage.entity.PatrolDetail;
import cn.stronglink.assetmanage.index.entity.PromissionEntity;
import cn.stronglink.assetmanage.utils.Constants;

/**
 * 操作待巡检界面
 * Created by zhengjinglan on 2018/6/12.
 */
public class WaitPatrolView implements IPatrolInView {
    private Fragment fragment;
    //未盘点资产列表布局
    @BindView(R.id.ll_patrol_order_name)
    LinearLayout ll_patrol_order_name;
    //表单
    @BindView(R.id.tv_patrol_order_name)
    TextView tv_patrol_order_name;
    //操作日期
    @BindView(R.id.tv_patrol_operation_date)
    TextView tv_patrol_operation_date;
    //未盘点表单列表
    @BindView(R.id.rv_patrol_order_list)
    RecyclerView rv_patrol_order_list;
    //每个表单中的资产列表
    @BindView(R.id.rv_patrol_list)
    ExpandableListView rv_patrol_list;
    //显示资产列表时，扫描操作布局
    @BindView(R.id.ll_patrol)
    LinearLayout ll_patrol;
    //表单列表adapter
    private  PatrolListAdapter listAdapter;
    //资产列表adapter
    private PatrolOrderAdapter orderAdapter;
    public WaitPatrolView(Fragment fragment, View view, PatrolListAdapter listAdapter, PatrolOrderAdapter orderAdapter) {
        this.fragment = fragment;
        ButterKnife.bind(this,view);

        this.listAdapter = listAdapter;
        this.orderAdapter = orderAdapter;
    }



    public Fragment getFragment() {
        return fragment;
    }


    /**
     * 显示未巡检资产列表
     */
    public void showAssetView(){
        rv_patrol_order_list.setVisibility(View.GONE);
        ll_patrol_order_name.setVisibility(View.VISIBLE);
        rv_patrol_list.setVisibility(View.VISIBLE);
        ll_patrol.setVisibility(View.VISIBLE);
    }

    /**
     *设置未盘点表单数据
     * @param inventoryList
     */
    public void setListData(List<Patrol> inventoryList){
        listAdapter.notifyDatasChanged(inventoryList);
    }


    /**
     * 显示未盘点资源列表表头
     */
    public void showAssetTitle(Patrol inventory){
        tv_patrol_order_name.setText(inventory.getId_());
        tv_patrol_operation_date.setText(inventory.getEndTime());
    }

    /**
     * 跳转到巡检详细界面
     * @param patrol
     */
    public void showOrderDetail(PatrolDetail  patrol){
        //跳转到详情页面

        MainActivity activity = (MainActivity) fragment.getActivity();
        PromissionEntity pe = new PromissionEntity();
        pe.setFragment(new PatrolDetailFragment());
        pe.setPosition(MainActivity.FRAGMENT_PATROL_DETAIL_ID);
        pe.setTitle("资产详情");
        // 设置打开盘点详情后传递的参数
        Bundle bundle=new Bundle();
        bundle.putSerializable(Constants.PATROL_DETAIL_NO, patrol.getAssetNo());
        pe.setBundle(bundle);
        activity.onEventRegister(pe);
    }

}


